package cn.thoughtworks.school.programCenter.repositories;

import cn.thoughtworks.school.programCenter.entities.QuizSuggestion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface QuizSuggestionRepository extends JpaRepository<QuizSuggestion, Long> {
    @Query(value = "select * from quizSuggestion where assignmentId=?1 and quizId=?2 and toUserId=?3 and parentId is null " +
            "union " +
            "select * from quizSuggestion where parentId in (select id from quizSuggestion where assignmentId=?1 and quizId=?2 and toUserId=?3 and parentId is null )" +
            "order by createTime asc ",
            nativeQuery = true)
    List<QuizSuggestion> findByAssignmentIdAndQuizIdAndStudentId(Long assignmentId, Long quizId, Long studentId);
}
